package com.code.pattern.strategy.factory;

import com.code.pattern.strategy.promotion.*;
import com.google.common.collect.Maps;

import java.util.Map;

/**
 * 促销策略工厂类
 * @author: liyufei
 * @date: 2021-04-01 20:19
 */
public class PromotionStrategyFactory {

    private PromotionStrategyFactory() {
    }

    private static Map<String, PromotionStrategy> PROMOTION_STRATEGY_MAP = Maps.newHashMap();

    static {
        PROMOTION_STRATEGY_MAP.put(PromotionKey.COUPON, new CouponStrategy());
        PROMOTION_STRATEGY_MAP.put(PromotionKey.CASHBACK, new CashbackStrategy());
        PROMOTION_STRATEGY_MAP.put(PromotionKey.GROUPBUY, new GroupBuyStrategy());
    }

    private static final PromotionStrategy NON_STRATEGY = new EmptyStrategy();

    public static PromotionStrategy getPromotionStrategy(String promotionKey) {
        PromotionStrategy promotionStrategy = PROMOTION_STRATEGY_MAP.get(promotionKey);
        return promotionStrategy != null ? promotionStrategy : NON_STRATEGY;
    }

    private interface PromotionKey {
        String COUPON = "COUPON";
        String CASHBACK = "CASHBACK";
        String GROUPBUY = "GROUPBUY";
    }
}
